import { ServerConfig } from "../src/config/ServerConfig"
import DateUtil from "../src/engine/utils/DateUtil"
import { HttpUtil } from "../src/engine/utils/HttpUtil"
import { LogMethodConfig } from "./LogMethodConfig"

export class LogServerHelper {

    public static sendLog(method: string, params: object) {
        let log_server: ServerConfig = ServerConfig.randomLogServer()
        HttpUtil.request_by_body(log_server.getInternalUrl() + method, params)
    }


    public static log_club_in_out_history(clubid: number, userid: number, in_out_type: number, handle_userid: number) {
        let logParam: object = {
            "clubid": clubid,
            "userid": userid,
            "handle_userid": handle_userid,
            "in_out_type": in_out_type,
            "time": DateUtil.formatDateStr(DateUtil.now()),
        }
        LogServerHelper.sendLog(LogMethodConfig.method_type.club_in_out_history, logParam)
    }

    public static log_club_top(clubid: number, userid: number, score: number, wintimes: number = 0, gametimes: number = 1) {
        let logParam: object = {
            "clubid": clubid,
            "userid": userid,
            "score": score,
            "wintimes": wintimes,
            "gametimes": gametimes,
        }
        LogServerHelper.sendLog(LogMethodConfig.method_type.club_top, logParam)
    }

    public static log_club_freeze_history(clubid: number, freezeid: number, handleid: number, freeze_type: number) {
        let logParam: object = {
            "clubid": clubid,
            "freezeid": freezeid,
            "handleid": handleid,
            "freeze_type": freeze_type,
        }
        LogServerHelper.sendLog(LogMethodConfig.method_type.club_freeze_history, logParam)
    }

    public static log_insert_give_history(sender: number, reciver: number, type: string, num: number) {
        let logParam: object = {
            "sender": sender,
            "reciver": reciver,
            "type": type,
            "num": num,
            "time": DateUtil.formatDateStr(DateUtil.now()),
        }
        LogServerHelper.sendLog(LogMethodConfig.method_type.insert_give_history, logParam)
    }

    public static log_add_user_spend_daily(userid: number, type: string, cost: number) {
        let logParam: object = {
            "userid": userid,
            "type": type,
            "cost": cost,
        }
        LogServerHelper.sendLog(LogMethodConfig.method_type.add_user_spend_daily, logParam)
    }

    public static log_add_user_gems_history(userid: number, gems: number, left_gems, reseason: string, detail: string) {
        let logParam: object = {
            "userid": userid,
            "gems": gems,
            "left_gems": left_gems,
            "reseason": reseason,
            "detail": detail,
            "time": DateUtil.formatDateStr(DateUtil.now()),
        }
        LogServerHelper.sendLog(LogMethodConfig.method_type.add_user_gems_history, logParam)
    }

    public static log_add_user_coins_history(userid: number, coins: number, left_coins, reseason: string, detail: string) {
        let logParam: object = {
            "userid": userid,
            "coins": coins,
            "left_coins": left_coins,
            "reseason": reseason,
            "detail": detail,
            "time": DateUtil.formatDateStr(DateUtil.now()),
        }
        LogServerHelper.sendLog(LogMethodConfig.method_type.add_user_coins_history, logParam)
    }

    public static log_add_user_income_history(userid: number, income: number, left_income: number, reaeason: string, detail: string) {

    }

    public static log_add_user_meilis_history(userid: number, meilis: number, left_meilis: number, reseason: string, detail: string) {
        let logParam: object = {
            "userid": userid,
            "meilis": meilis,
            "left_meilis": left_meilis,
            "reseason": reseason,
            "detail": detail,
            "time": DateUtil.formatDateStr(DateUtil.now()),
        }
        LogServerHelper.sendLog(LogMethodConfig.method_type.add_user_meilis_history, logParam)
    }

    public static log_room_statistics(room_id: number, clubid: number, time: number) {
        if(clubid > 0){
            let logParam: object = {
                "room_id": room_id,
                "clubid": clubid,
                "time": time
            }
            LogServerHelper.sendLog(LogMethodConfig.method_type.add_room_statistics, logParam)
        }
    }

}